package cn.tedu._06notice.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;
    // 1.构造方法：针对于没有具体数据返回的控制器方法，比如添加资讯、删除资讯、修改资讯
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getCode();
        this.message = statusCode.getMessage();
    }
    // 2.构造方法：针对于有具体数据返回的控制器方法，比如查询资讯列表、查询资讯详情
    public JsonResult(StatusCode statusCode, Object data){
        this.state = statusCode.getCode();
        this.message = statusCode.getMessage();
        this.data = data;
    }
    // 针对操作成功的场景，封装2个静态方法
    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    public static JsonResult ok() {
        return ok(null);
    }
}
